﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyControl;

public partial class CSS_DualListBox_demoDualListBox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (int i = 0; i < 10; i++)
            {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                box1View.Items.Add(item);
            }

            for (int i = 10; i < 20; i++)
            {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                box2View.Items.Add(item);
            }
        }
    }

    private void RegisterForEventValidation(ListBox lb)
    {
        ClientScript.RegisterForEventValidation(
                lb.UniqueID);

#if false
        foreach (ListItem item in box1View.Items)
        {
            ClientScript.RegisterForEventValidation(
                lb.UniqueID, item.Value);
        }
#endif
    }

    protected override void Render(HtmlTextWriter writer)
    {
        ListBox[] lbs = { box1Storage, box2View, box2Storage };

        foreach (ListBox lb in lbs)
            RegisterForEventValidation(lb);

        base.Render(writer);
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        object o = Request.Form[box1View.ClientID];
        o = Request.Form[box2View.ClientID];

        //string result = string.Empty;
        string result = "Result";

        foreach (ListItem item in box2View.Items)
        {
            if (result.Length!=0)
                result += ",";

            result += item.Value;
        }

        Result.Text = result;
    }
}
